package com.yanqu.road.server.cmd.banquet;

import com.yanqu.road.pb.banquet.CrossBanquetProto;
import com.yanqu.road.pb.worldmessage.WorldMessageProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.banquet.CrossBanquetChatMgr;
import com.yanqu.road.server.manager.banquet.CrossPartyChatMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_CROSS_BANQUET_CHAT_LIST, desc = "跨服宴会聊天列表")
public class CrossBanquetChatListCmd extends CrossCommand {
    private String banquetId;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        CrossBanquetProto.CrossBanquetChatListReqMsg reqMsg = CrossBanquetProto.CrossBanquetChatListReqMsg.parseFrom(packet.getBytes());
        banquetId = reqMsg.getBanquetId();
        userId = packet.getPlayerId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        WorldMessageProto.WorldMessageListMsg.Builder msg = CrossBanquetChatMgr.getChatListMsg(banquetId);
        if (msg == null) {
            msg = CrossPartyChatMgr.getChatListMsg(banquetId);
        }
        CrossBanquetProto.CrossBanquetChatListRespMsg.Builder respMsg = CrossBanquetProto.CrossBanquetChatListRespMsg.newBuilder();
        respMsg.setBanquetId(banquetId);
        if(null != msg) {
            respMsg.setDataList(msg);
        }
        YanQuMessage pbMsg = YanQuMessageUtils.buildMessage(Protocol.S_CROSS_BANQUET_CHAT_LIST_NOTIFY, respMsg);
        MessageHelper.sendPacket(serverId, userId, pbMsg);
    }

    @Override
    public void sendData() {

    }
}
